<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" />
<link rel="stylesheet" href="/static/ui/css/ui.css" />
</head>
<body>
<form class="layui-form" action="" lay-filter="editform">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" name="no" lay-verify="required" autocomplete="off" min="1" placeholder="请输入采购编号" class="layui-input">
                    </div>
                </div>
            <div class="layui-form-item">
                <label class="layui-form-label">预算项目</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" autocomplete="off" min="1" placeholder="请输入采购名称" class="layui-input">
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label">预算费用</label>
                <div class="layui-input-block">
                    <input type="number" name="all_price" lay-verify="required" autocomplete="off" min="0" placeholder="请输入采购名称" class="layui-input">
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label">配套数量</label>
                <div class="layui-input-block">
                    <input type="number" name="num" lay-verify="required" autocomplete="off" min="0" placeholder="请输入采购名称" class="layui-input">
                </div>
            </div>
			
			<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label">预算说明</label>
			    <div class="layui-input-block">
			        <textarea name="remark" placeholder="请输入预算说明" class="layui-textarea"></textarea>
			    </div>
			</div>
			

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
			<input  type="hidden" name="id"/>
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="purchase-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
        </div>
    </div>
</form>
<script src="../config.js"></script>
<script src="/static/layui/layui.js"></script>
<script src="/static/ui/ui.js"></script>
<script>
    layui.use(['form','layer','tree','laydate','util'], function () {
        let form = layui.form
            , layer = layui.layer
			, laydate = layui.laydate
			, $ = layui.$
            , req = _req();
		  laydate.render({ 
		    elem: '#test-range' //开始时间和结束时间所在 input 框的父选择器
		    //设置开始日期、日期日期的 input 选择器
		    ,range: ['#startDate', '#endDate'] //数组格式为 layui 2.6.6 开始新增
		  });
        form.verify({
            len : (val, item) => {
                let min = item.getAttribute("min")
                if(val.length < min) {
                    return '长度不能小于' + min;
                }
            }
        })
        if(req.id) {
            //渲染
            _get(layui, 'purchase/editOneBefore?id=' + req.id, res => {
				form.val('editform', res)
            });
        }

        //监听提交
        form.on('submit(purchase-save)', function (data) {
			data = data.field;
            let postUrl;
            if(req.id) {
                postUrl = 'purchase/editOne';
            }else{
                postUrl = 'purchase/addOne';
            }
            data.pur_id = req.pur_id;
			_post(layui, postUrl, data, res => {
				//console.log(res)
				parent.layui.table.reload("pur-type-table");
				parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页

			})

            return false;
        });

    });
</script>

</body>
</html>